package com.share.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author sunxuejian
 * @date 2020/4/20
 */
public class MyFilter1 implements Filter {

    public MyFilter1() {
        System.out.println("-------------------> filter1构造方法" );
    }

    private FilterConfig filterConfig;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("-------------------> filter1---init" );
        this.filterConfig = filterConfig;

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        System.out.println("------------去--------->doFilter1");


        String encoding = filterConfig.getInitParameter("encoding");
        System.out.println("----------->encoding:" + encoding);
        request.setCharacterEncoding(encoding);


        //放行
        chain.doFilter(request, response);


        System.out.println("------------回--------->doFilter1");
    }

    @Override
    public void destroy() {

    }
}
